{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1495814 entries, 0 to 1495813\n",
      "Data columns (total 5 columns):\n",
      "start_time    1495814 non-null object\n",
      "start_lat     1495814 non-null float64\n",
      "start_lon     1495814 non-null float64\n",
      "end_lat       1495814 non-null float64\n",
      "end_lon       1495814 non-null float64\n",
      "dtypes: float64(4), object(1)\n",
      "memory usage: 57.1+ MB\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import os\n",
    "import geohash\n",
    "import numpy as np\n",
    "\n",
    "import warnings\n",
    "\n",
    "warnings.filterwarnings('ignore')\n",
    "processedDf = df = pd.read_csv('/home/data/train_new.csv',\n",
    "                 usecols=['start_time', 'end_time', 'start_lat', 'start_lon', 'end_lat', 'end_lon'])\n",
    "processedDf.drop('end_time',axis=1,inplace=True)\n",
    "processedDf.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_time</th>\n",
       "      <th>start_lat</th>\n",
       "      <th>start_lon</th>\n",
       "      <th>end_lat</th>\n",
       "      <th>end_lon</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-20 10:13:43</td>\n",
       "      <td>33.783415</td>\n",
       "      <td>111.603660</td>\n",
       "      <td>33.779811</td>\n",
       "      <td>111.605885</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-02-12 17:40:51</td>\n",
       "      <td>34.810763</td>\n",
       "      <td>115.549264</td>\n",
       "      <td>34.814875</td>\n",
       "      <td>115.549374</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-02-13 14:52:24</td>\n",
       "      <td>34.640284</td>\n",
       "      <td>115.539024</td>\n",
       "      <td>34.813136</td>\n",
       "      <td>115.559243</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-02-13 17:23:08</td>\n",
       "      <td>34.818280</td>\n",
       "      <td>115.542039</td>\n",
       "      <td>34.813141</td>\n",
       "      <td>115.559217</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-02-13 18:06:02</td>\n",
       "      <td>34.813278</td>\n",
       "      <td>115.559260</td>\n",
       "      <td>34.786126</td>\n",
       "      <td>115.874361</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            start_time  start_lat   start_lon    end_lat     end_lon\n",
       "0  2018-01-20 10:13:43  33.783415  111.603660  33.779811  111.605885\n",
       "1  2018-02-12 17:40:51  34.810763  115.549264  34.814875  115.549374\n",
       "2  2018-02-13 14:52:24  34.640284  115.539024  34.813136  115.559243\n",
       "3  2018-02-13 17:23:08  34.818280  115.542039  34.813141  115.559217\n",
       "4  2018-02-13 18:06:02  34.813278  115.559260  34.786126  115.874361"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "processedDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "dateDf = pd.DataFrame()\n",
    "dateDf['date']=pd.to_datetime(processedDf['start_time'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-20 10:13:43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-02-12 17:40:51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-02-13 14:52:24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-02-13 17:23:08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-02-13 18:06:02</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 date\n",
       "0 2018-01-20 10:13:43\n",
       "1 2018-02-12 17:40:51\n",
       "2 2018-02-13 14:52:24\n",
       "3 2018-02-13 17:23:08\n",
       "4 2018-02-13 18:06:02"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dateDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "dateDf['date']=pd.to_datetime(dateDf['date']).dt.weekday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   date\n",
       "0     5\n",
       "1     0\n",
       "2     1\n",
       "3     1\n",
       "4     1"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dateDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "weekendDf = pd.DataFrame()\n",
    "weekend={0:0,\n",
    "         1:0,\n",
    "         2:0,\n",
    "         3:0,\n",
    "         4:0,\n",
    "         5:1,\n",
    "         6:1\n",
    "         \n",
    "}\n",
    "weekendDf['weekend'] = dateDf['date'].map(weekend)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>weekend</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   weekend\n",
       "0        1\n",
       "1        0\n",
       "2        0\n",
       "3        0\n",
       "4        0"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "weekendDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_time</th>\n",
       "      <th>start_lat</th>\n",
       "      <th>start_lon</th>\n",
       "      <th>end_lat</th>\n",
       "      <th>end_lon</th>\n",
       "      <th>weekend</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-20 10:13:43</td>\n",
       "      <td>33.783415</td>\n",
       "      <td>111.603660</td>\n",
       "      <td>33.779811</td>\n",
       "      <td>111.605885</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-02-12 17:40:51</td>\n",
       "      <td>34.810763</td>\n",
       "      <td>115.549264</td>\n",
       "      <td>34.814875</td>\n",
       "      <td>115.549374</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-02-13 14:52:24</td>\n",
       "      <td>34.640284</td>\n",
       "      <td>115.539024</td>\n",
       "      <td>34.813136</td>\n",
       "      <td>115.559243</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-02-13 17:23:08</td>\n",
       "      <td>34.818280</td>\n",
       "      <td>115.542039</td>\n",
       "      <td>34.813141</td>\n",
       "      <td>115.559217</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-02-13 18:06:02</td>\n",
       "      <td>34.813278</td>\n",
       "      <td>115.559260</td>\n",
       "      <td>34.786126</td>\n",
       "      <td>115.874361</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            start_time  start_lat   start_lon    end_lat     end_lon  weekend\n",
       "0  2018-01-20 10:13:43  33.783415  111.603660  33.779811  111.605885        1\n",
       "1  2018-02-12 17:40:51  34.810763  115.549264  34.814875  115.549374        0\n",
       "2  2018-02-13 14:52:24  34.640284  115.539024  34.813136  115.559243        0\n",
       "3  2018-02-13 17:23:08  34.818280  115.542039  34.813141  115.559217        0\n",
       "4  2018-02-13 18:06:02  34.813278  115.559260  34.786126  115.874361        0"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "processedDf = pd.concat([processedDf,weekendDf],axis=1)\n",
    "processedDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "yearDf = pd.DataFrame()\n",
    "monthDf = pd.DataFrame()\n",
    "dayDf = pd.DataFrame()\n",
    "strDf = pd.DataFrame()\n",
    "dateDf['date']=pd.to_datetime(processedDf['start_time'])#重新初始化\n",
    "yearDf['year']=pd.to_datetime(dateDf['date']).dt.year\n",
    "monthDf['month']=pd.to_datetime(dateDf['date']).dt.month\n",
    "dayDf['day']=pd.to_datetime(dateDf['date']).dt.day\n",
    "strDf['day']=pd.to_datetime(dateDf['date']).dt.day"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_time</th>\n",
       "      <th>start_lat</th>\n",
       "      <th>start_lon</th>\n",
       "      <th>end_lat</th>\n",
       "      <th>end_lon</th>\n",
       "      <th>weekend</th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>day</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-20 10:13:43</td>\n",
       "      <td>33.783415</td>\n",
       "      <td>111.603660</td>\n",
       "      <td>33.779811</td>\n",
       "      <td>111.605885</td>\n",
       "      <td>1</td>\n",
       "      <td>2018</td>\n",
       "      <td>1</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-02-12 17:40:51</td>\n",
       "      <td>34.810763</td>\n",
       "      <td>115.549264</td>\n",
       "      <td>34.814875</td>\n",
       "      <td>115.549374</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-02-13 14:52:24</td>\n",
       "      <td>34.640284</td>\n",
       "      <td>115.539024</td>\n",
       "      <td>34.813136</td>\n",
       "      <td>115.559243</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-02-13 17:23:08</td>\n",
       "      <td>34.818280</td>\n",
       "      <td>115.542039</td>\n",
       "      <td>34.813141</td>\n",
       "      <td>115.559217</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-02-13 18:06:02</td>\n",
       "      <td>34.813278</td>\n",
       "      <td>115.559260</td>\n",
       "      <td>34.786126</td>\n",
       "      <td>115.874361</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            start_time  start_lat   start_lon    end_lat     end_lon  weekend  \\\n",
       "0  2018-01-20 10:13:43  33.783415  111.603660  33.779811  111.605885        1   \n",
       "1  2018-02-12 17:40:51  34.810763  115.549264  34.814875  115.549374        0   \n",
       "2  2018-02-13 14:52:24  34.640284  115.539024  34.813136  115.559243        0   \n",
       "3  2018-02-13 17:23:08  34.818280  115.542039  34.813141  115.559217        0   \n",
       "4  2018-02-13 18:06:02  34.813278  115.559260  34.786126  115.874361        0   \n",
       "\n",
       "   year  month  day  \n",
       "0  2018      1   20  \n",
       "1  2018      2   12  \n",
       "2  2018      2   13  \n",
       "3  2018      2   13  \n",
       "4  2018      2   13  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "processedDf = pd.concat([processedDf,yearDf],axis=1)\n",
    "processedDf = pd.concat([processedDf,monthDf],axis=1)\n",
    "processedDf = pd.concat([processedDf,dayDf],axis=1)\n",
    "processedDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "hourDf = pd.DataFrame()\n",
    "minuteDf = pd.DataFrame()\n",
    "hourDf['hour']=pd.to_datetime(dateDf['date']).dt.hour\n",
    "minuteDf['minute']=pd.to_datetime(dateDf['date']).dt.minute"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>hour</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   hour\n",
       "0    10\n",
       "1    17\n",
       "2    14\n",
       "3    17\n",
       "4    18"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hourDf.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "以下是time_cat测试代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>hour</th>\n",
       "      <th>minute</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>17</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>14</td>\n",
       "      <td>52</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>17</td>\n",
       "      <td>23</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>18</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   hour  minute\n",
       "0    10      13\n",
       "1    17      40\n",
       "2    14      52\n",
       "3    17      23\n",
       "4    18       6"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hourDf = pd.concat([hourDf,minuteDf],axis=1)\n",
    "hourDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1495814 entries, 0 to 1495813\n",
      "Data columns (total 2 columns):\n",
      "hour      1495814 non-null int64\n",
      "minute    1495814 non-null int64\n",
      "dtypes: int64(2)\n",
      "memory usage: 22.8 MB\n"
     ]
    }
   ],
   "source": [
    "hourDf.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "def time_cat(hour,minute):\n",
    "    hour = str(hour)\n",
    "    minute = str(int(minute/15)*15)\n",
    "    return hour + \":\" + minute\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>hour</th>\n",
       "      <th>minute</th>\n",
       "      <th>time_cat</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>13</td>\n",
       "      <td>10:0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>17</td>\n",
       "      <td>40</td>\n",
       "      <td>17:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>14</td>\n",
       "      <td>52</td>\n",
       "      <td>14:45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>17</td>\n",
       "      <td>23</td>\n",
       "      <td>17:15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>18</td>\n",
       "      <td>6</td>\n",
       "      <td>18:0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   hour  minute time_cat\n",
       "0    10      13     10:0\n",
       "1    17      40    17:30\n",
       "2    14      52    14:45\n",
       "3    17      23    17:15\n",
       "4    18       6     18:0"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hourDf['time_cat'] = hourDf.apply(lambda row:time_cat(row['hour'],row['minute']),axis=1)\n",
    "hourDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_time</th>\n",
       "      <th>start_lat</th>\n",
       "      <th>start_lon</th>\n",
       "      <th>end_lat</th>\n",
       "      <th>end_lon</th>\n",
       "      <th>weekend</th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>day</th>\n",
       "      <th>time_cat</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-20 10:13:43</td>\n",
       "      <td>33.783415</td>\n",
       "      <td>111.603660</td>\n",
       "      <td>33.779811</td>\n",
       "      <td>111.605885</td>\n",
       "      <td>1</td>\n",
       "      <td>2018</td>\n",
       "      <td>1</td>\n",
       "      <td>20</td>\n",
       "      <td>10:0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-02-12 17:40:51</td>\n",
       "      <td>34.810763</td>\n",
       "      <td>115.549264</td>\n",
       "      <td>34.814875</td>\n",
       "      <td>115.549374</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>12</td>\n",
       "      <td>17:30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-02-13 14:52:24</td>\n",
       "      <td>34.640284</td>\n",
       "      <td>115.539024</td>\n",
       "      <td>34.813136</td>\n",
       "      <td>115.559243</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>14:45</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-02-13 17:23:08</td>\n",
       "      <td>34.818280</td>\n",
       "      <td>115.542039</td>\n",
       "      <td>34.813141</td>\n",
       "      <td>115.559217</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>17:15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-02-13 18:06:02</td>\n",
       "      <td>34.813278</td>\n",
       "      <td>115.559260</td>\n",
       "      <td>34.786126</td>\n",
       "      <td>115.874361</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>18:0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            start_time  start_lat   start_lon    end_lat     end_lon  weekend  \\\n",
       "0  2018-01-20 10:13:43  33.783415  111.603660  33.779811  111.605885        1   \n",
       "1  2018-02-12 17:40:51  34.810763  115.549264  34.814875  115.549374        0   \n",
       "2  2018-02-13 14:52:24  34.640284  115.539024  34.813136  115.559243        0   \n",
       "3  2018-02-13 17:23:08  34.818280  115.542039  34.813141  115.559217        0   \n",
       "4  2018-02-13 18:06:02  34.813278  115.559260  34.786126  115.874361        0   \n",
       "\n",
       "   year  month  day time_cat  \n",
       "0  2018      1   20     10:0  \n",
       "1  2018      2   12    17:30  \n",
       "2  2018      2   13    14:45  \n",
       "3  2018      2   13    17:15  \n",
       "4  2018      2   13     18:0  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "processedDf.loc[:,\"time_cat\"] = hourDf.loc[:,\"time_cat\"]\n",
    "processedDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "def time_num(hour,minute):\n",
    "    per = (hour*60+minute)/(60*24)\n",
    "    return per"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "hourDf['time_num']=hourDf.apply(lambda row:time_num(row['hour'],row['minute']),axis=1)\n",
    "processedDf.loc[:,\"time_num\"] = hourDf.loc[:,\"time_num\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_time</th>\n",
       "      <th>start_lat</th>\n",
       "      <th>start_lon</th>\n",
       "      <th>end_lat</th>\n",
       "      <th>end_lon</th>\n",
       "      <th>weekend</th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>day</th>\n",
       "      <th>time_cat</th>\n",
       "      <th>time_num</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-20 10:13:43</td>\n",
       "      <td>33.783415</td>\n",
       "      <td>111.603660</td>\n",
       "      <td>33.779811</td>\n",
       "      <td>111.605885</td>\n",
       "      <td>1</td>\n",
       "      <td>2018</td>\n",
       "      <td>1</td>\n",
       "      <td>20</td>\n",
       "      <td>10:0</td>\n",
       "      <td>0.425694</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-02-12 17:40:51</td>\n",
       "      <td>34.810763</td>\n",
       "      <td>115.549264</td>\n",
       "      <td>34.814875</td>\n",
       "      <td>115.549374</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>12</td>\n",
       "      <td>17:30</td>\n",
       "      <td>0.736111</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-02-13 14:52:24</td>\n",
       "      <td>34.640284</td>\n",
       "      <td>115.539024</td>\n",
       "      <td>34.813136</td>\n",
       "      <td>115.559243</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>14:45</td>\n",
       "      <td>0.619444</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-02-13 17:23:08</td>\n",
       "      <td>34.818280</td>\n",
       "      <td>115.542039</td>\n",
       "      <td>34.813141</td>\n",
       "      <td>115.559217</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>17:15</td>\n",
       "      <td>0.724306</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-02-13 18:06:02</td>\n",
       "      <td>34.813278</td>\n",
       "      <td>115.559260</td>\n",
       "      <td>34.786126</td>\n",
       "      <td>115.874361</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>18:0</td>\n",
       "      <td>0.754167</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            start_time  start_lat   start_lon    end_lat     end_lon  weekend  \\\n",
       "0  2018-01-20 10:13:43  33.783415  111.603660  33.779811  111.605885        1   \n",
       "1  2018-02-12 17:40:51  34.810763  115.549264  34.814875  115.549374        0   \n",
       "2  2018-02-13 14:52:24  34.640284  115.539024  34.813136  115.559243        0   \n",
       "3  2018-02-13 17:23:08  34.818280  115.542039  34.813141  115.559217        0   \n",
       "4  2018-02-13 18:06:02  34.813278  115.559260  34.786126  115.874361        0   \n",
       "\n",
       "   year  month  day time_cat  time_num  \n",
       "0  2018      1   20     10:0  0.425694  \n",
       "1  2018      2   12    17:30  0.736111  \n",
       "2  2018      2   13    14:45  0.619444  \n",
       "3  2018      2   13    17:15  0.724306  \n",
       "4  2018      2   13     18:0  0.754167  "
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "processedDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "def time_cos(time_num):\n",
    "    item = math.cos(time_num*2*math.pi)\n",
    "    return item\n",
    "def time_sin(time_num):\n",
    "    item = math.sin(time_num*2*math.pi)\n",
    "    return item"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_time</th>\n",
       "      <th>start_lat</th>\n",
       "      <th>start_lon</th>\n",
       "      <th>end_lat</th>\n",
       "      <th>end_lon</th>\n",
       "      <th>weekend</th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>day</th>\n",
       "      <th>time_cat</th>\n",
       "      <th>time_num</th>\n",
       "      <th>time_cos</th>\n",
       "      <th>time_sin</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-20 10:13:43</td>\n",
       "      <td>33.783415</td>\n",
       "      <td>111.603660</td>\n",
       "      <td>33.779811</td>\n",
       "      <td>111.605885</td>\n",
       "      <td>1</td>\n",
       "      <td>2018</td>\n",
       "      <td>1</td>\n",
       "      <td>20</td>\n",
       "      <td>10:0</td>\n",
       "      <td>0.425694</td>\n",
       "      <td>-0.892979</td>\n",
       "      <td>0.450098</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-02-12 17:40:51</td>\n",
       "      <td>34.810763</td>\n",
       "      <td>115.549264</td>\n",
       "      <td>34.814875</td>\n",
       "      <td>115.549374</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>12</td>\n",
       "      <td>17:30</td>\n",
       "      <td>0.736111</td>\n",
       "      <td>-0.087156</td>\n",
       "      <td>-0.996195</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-02-13 14:52:24</td>\n",
       "      <td>34.640284</td>\n",
       "      <td>115.539024</td>\n",
       "      <td>34.813136</td>\n",
       "      <td>115.559243</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>14:45</td>\n",
       "      <td>0.619444</td>\n",
       "      <td>-0.731354</td>\n",
       "      <td>-0.681998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-02-13 17:23:08</td>\n",
       "      <td>34.818280</td>\n",
       "      <td>115.542039</td>\n",
       "      <td>34.813141</td>\n",
       "      <td>115.559217</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>17:15</td>\n",
       "      <td>0.724306</td>\n",
       "      <td>-0.160743</td>\n",
       "      <td>-0.986996</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-02-13 18:06:02</td>\n",
       "      <td>34.813278</td>\n",
       "      <td>115.559260</td>\n",
       "      <td>34.786126</td>\n",
       "      <td>115.874361</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>18:0</td>\n",
       "      <td>0.754167</td>\n",
       "      <td>0.026177</td>\n",
       "      <td>-0.999657</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            start_time  start_lat   start_lon    end_lat     end_lon  weekend  \\\n",
       "0  2018-01-20 10:13:43  33.783415  111.603660  33.779811  111.605885        1   \n",
       "1  2018-02-12 17:40:51  34.810763  115.549264  34.814875  115.549374        0   \n",
       "2  2018-02-13 14:52:24  34.640284  115.539024  34.813136  115.559243        0   \n",
       "3  2018-02-13 17:23:08  34.818280  115.542039  34.813141  115.559217        0   \n",
       "4  2018-02-13 18:06:02  34.813278  115.559260  34.786126  115.874361        0   \n",
       "\n",
       "   year  month  day time_cat  time_num  time_cos  time_sin  \n",
       "0  2018      1   20     10:0  0.425694 -0.892979  0.450098  \n",
       "1  2018      2   12    17:30  0.736111 -0.087156 -0.996195  \n",
       "2  2018      2   13    14:45  0.619444 -0.731354 -0.681998  \n",
       "3  2018      2   13    17:15  0.724306 -0.160743 -0.986996  \n",
       "4  2018      2   13     18:0  0.754167  0.026177 -0.999657  "
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hourDf['time_cos']=hourDf.apply(lambda row:time_cos(row['time_num']),axis=1)\n",
    "hourDf['time_sin']=hourDf.apply(lambda row:time_sin(row['time_num']),axis=1)\n",
    "processedDf.loc[:,\"time_cos\"] = hourDf.loc[:,\"time_cos\"]\n",
    "processedDf.loc[:,\"time_sin\"] = hourDf.loc[:,\"time_sin\"]\n",
    "processedDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-20 10:13:43</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-02-12 17:40:51</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-02-13 14:52:24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-02-13 17:23:08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-02-13 18:06:02</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 date\n",
       "0 2018-01-20 10:13:43\n",
       "1 2018-02-12 17:40:51\n",
       "2 2018-02-13 14:52:24\n",
       "3 2018-02-13 17:23:08\n",
       "4 2018-02-13 18:06:02"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dateDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>day</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-20 10:13:43</td>\n",
       "      <td>Saturday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-02-12 17:40:51</td>\n",
       "      <td>Monday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-02-13 14:52:24</td>\n",
       "      <td>Tuesday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-02-13 17:23:08</td>\n",
       "      <td>Tuesday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-02-13 18:06:02</td>\n",
       "      <td>Tuesday</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 date       day\n",
       "0 2018-01-20 10:13:43  Saturday\n",
       "1 2018-02-12 17:40:51    Monday\n",
       "2 2018-02-13 14:52:24   Tuesday\n",
       "3 2018-02-13 17:23:08   Tuesday\n",
       "4 2018-02-13 18:06:02   Tuesday"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dateDf['day']=pd.to_datetime(dateDf['date']).dt.weekday\n",
    "day_to_str = {0: \"Monday\",\n",
    "              1: \"Tuesday\",\n",
    "              2: \"Wednesday\",\n",
    "              3: \"Thursday\",\n",
    "              4: \"Friday\",\n",
    "              5: \"Saturday\",\n",
    "              6: \"Sunday\"}\n",
    "dateDf['day'] = dateDf['day'].map(day_to_str)\n",
    "dateDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "processedDf.loc[:,\"day_cat\"] = dateDf.loc[:,\"day\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>hour</th>\n",
       "      <th>minute</th>\n",
       "      <th>time_cat</th>\n",
       "      <th>time_num</th>\n",
       "      <th>time_cos</th>\n",
       "      <th>time_sin</th>\n",
       "      <th>day_index</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>13</td>\n",
       "      <td>10:0</td>\n",
       "      <td>0.425694</td>\n",
       "      <td>-0.892979</td>\n",
       "      <td>0.450098</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>17</td>\n",
       "      <td>40</td>\n",
       "      <td>17:30</td>\n",
       "      <td>0.736111</td>\n",
       "      <td>-0.087156</td>\n",
       "      <td>-0.996195</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>14</td>\n",
       "      <td>52</td>\n",
       "      <td>14:45</td>\n",
       "      <td>0.619444</td>\n",
       "      <td>-0.731354</td>\n",
       "      <td>-0.681998</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>17</td>\n",
       "      <td>23</td>\n",
       "      <td>17:15</td>\n",
       "      <td>0.724306</td>\n",
       "      <td>-0.160743</td>\n",
       "      <td>-0.986996</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>18</td>\n",
       "      <td>6</td>\n",
       "      <td>18:0</td>\n",
       "      <td>0.754167</td>\n",
       "      <td>0.026177</td>\n",
       "      <td>-0.999657</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   hour  minute time_cat  time_num  time_cos  time_sin  day_index\n",
       "0    10      13     10:0  0.425694 -0.892979  0.450098          5\n",
       "1    17      40    17:30  0.736111 -0.087156 -0.996195          0\n",
       "2    14      52    14:45  0.619444 -0.731354 -0.681998          1\n",
       "3    17      23    17:15  0.724306 -0.160743 -0.986996          1\n",
       "4    18       6     18:0  0.754167  0.026177 -0.999657          1"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hourDf['day_index']=pd.to_datetime(dateDf['date']).dt.weekday\n",
    "hourDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "def day_num(time_num,day_index):\n",
    "    per = (day_index+time_num)/7\n",
    "    return per"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_time</th>\n",
       "      <th>start_lat</th>\n",
       "      <th>start_lon</th>\n",
       "      <th>end_lat</th>\n",
       "      <th>end_lon</th>\n",
       "      <th>weekend</th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>day</th>\n",
       "      <th>time_cat</th>\n",
       "      <th>time_num</th>\n",
       "      <th>time_cos</th>\n",
       "      <th>time_sin</th>\n",
       "      <th>day_cat</th>\n",
       "      <th>day_num</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-20 10:13:43</td>\n",
       "      <td>33.783415</td>\n",
       "      <td>111.603660</td>\n",
       "      <td>33.779811</td>\n",
       "      <td>111.605885</td>\n",
       "      <td>1</td>\n",
       "      <td>2018</td>\n",
       "      <td>1</td>\n",
       "      <td>20</td>\n",
       "      <td>10:0</td>\n",
       "      <td>0.425694</td>\n",
       "      <td>-0.892979</td>\n",
       "      <td>0.450098</td>\n",
       "      <td>Saturday</td>\n",
       "      <td>0.775099</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-02-12 17:40:51</td>\n",
       "      <td>34.810763</td>\n",
       "      <td>115.549264</td>\n",
       "      <td>34.814875</td>\n",
       "      <td>115.549374</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>12</td>\n",
       "      <td>17:30</td>\n",
       "      <td>0.736111</td>\n",
       "      <td>-0.087156</td>\n",
       "      <td>-0.996195</td>\n",
       "      <td>Monday</td>\n",
       "      <td>0.105159</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-02-13 14:52:24</td>\n",
       "      <td>34.640284</td>\n",
       "      <td>115.539024</td>\n",
       "      <td>34.813136</td>\n",
       "      <td>115.559243</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>14:45</td>\n",
       "      <td>0.619444</td>\n",
       "      <td>-0.731354</td>\n",
       "      <td>-0.681998</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>0.231349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-02-13 17:23:08</td>\n",
       "      <td>34.818280</td>\n",
       "      <td>115.542039</td>\n",
       "      <td>34.813141</td>\n",
       "      <td>115.559217</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>17:15</td>\n",
       "      <td>0.724306</td>\n",
       "      <td>-0.160743</td>\n",
       "      <td>-0.986996</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>0.246329</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-02-13 18:06:02</td>\n",
       "      <td>34.813278</td>\n",
       "      <td>115.559260</td>\n",
       "      <td>34.786126</td>\n",
       "      <td>115.874361</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>18:0</td>\n",
       "      <td>0.754167</td>\n",
       "      <td>0.026177</td>\n",
       "      <td>-0.999657</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>0.250595</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            start_time  start_lat   start_lon    end_lat     end_lon  weekend  \\\n",
       "0  2018-01-20 10:13:43  33.783415  111.603660  33.779811  111.605885        1   \n",
       "1  2018-02-12 17:40:51  34.810763  115.549264  34.814875  115.549374        0   \n",
       "2  2018-02-13 14:52:24  34.640284  115.539024  34.813136  115.559243        0   \n",
       "3  2018-02-13 17:23:08  34.818280  115.542039  34.813141  115.559217        0   \n",
       "4  2018-02-13 18:06:02  34.813278  115.559260  34.786126  115.874361        0   \n",
       "\n",
       "   year  month  day time_cat  time_num  time_cos  time_sin   day_cat   day_num  \n",
       "0  2018      1   20     10:0  0.425694 -0.892979  0.450098  Saturday  0.775099  \n",
       "1  2018      2   12    17:30  0.736111 -0.087156 -0.996195    Monday  0.105159  \n",
       "2  2018      2   13    14:45  0.619444 -0.731354 -0.681998   Tuesday  0.231349  \n",
       "3  2018      2   13    17:15  0.724306 -0.160743 -0.986996   Tuesday  0.246329  \n",
       "4  2018      2   13     18:0  0.754167  0.026177 -0.999657   Tuesday  0.250595  "
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hourDf['day_num']=hourDf.apply(lambda row:day_num(row['time_num'],row['day_index']),axis=1)\n",
    "processedDf.loc[:,\"day_num\"] = hourDf.loc[:,\"day_num\"]\n",
    "processedDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "def day_cos(day_num):\n",
    "    per = math.cos(day_num*2*math.pi)\n",
    "    return per\n",
    "def day_sin(day_num):\n",
    "    per = math.sin(day_num*2*math.pi)\n",
    "    return per"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_time</th>\n",
       "      <th>start_lat</th>\n",
       "      <th>start_lon</th>\n",
       "      <th>end_lat</th>\n",
       "      <th>end_lon</th>\n",
       "      <th>weekend</th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>day</th>\n",
       "      <th>time_cat</th>\n",
       "      <th>time_num</th>\n",
       "      <th>time_cos</th>\n",
       "      <th>time_sin</th>\n",
       "      <th>day_cat</th>\n",
       "      <th>day_num</th>\n",
       "      <th>day_cos</th>\n",
       "      <th>day_sin</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-20 10:13:43</td>\n",
       "      <td>33.783415</td>\n",
       "      <td>111.603660</td>\n",
       "      <td>33.779811</td>\n",
       "      <td>111.605885</td>\n",
       "      <td>1</td>\n",
       "      <td>2018</td>\n",
       "      <td>1</td>\n",
       "      <td>20</td>\n",
       "      <td>10:0</td>\n",
       "      <td>0.425694</td>\n",
       "      <td>-0.892979</td>\n",
       "      <td>0.450098</td>\n",
       "      <td>Saturday</td>\n",
       "      <td>0.775099</td>\n",
       "      <td>0.157050</td>\n",
       "      <td>-0.987591</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-02-12 17:40:51</td>\n",
       "      <td>34.810763</td>\n",
       "      <td>115.549264</td>\n",
       "      <td>34.814875</td>\n",
       "      <td>115.549374</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>12</td>\n",
       "      <td>17:30</td>\n",
       "      <td>0.736111</td>\n",
       "      <td>-0.087156</td>\n",
       "      <td>-0.996195</td>\n",
       "      <td>Monday</td>\n",
       "      <td>0.105159</td>\n",
       "      <td>0.789543</td>\n",
       "      <td>0.613695</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-02-13 14:52:24</td>\n",
       "      <td>34.640284</td>\n",
       "      <td>115.539024</td>\n",
       "      <td>34.813136</td>\n",
       "      <td>115.559243</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>14:45</td>\n",
       "      <td>0.619444</td>\n",
       "      <td>-0.731354</td>\n",
       "      <td>-0.681998</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>0.231349</td>\n",
       "      <td>0.116918</td>\n",
       "      <td>0.993142</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-02-13 17:23:08</td>\n",
       "      <td>34.818280</td>\n",
       "      <td>115.542039</td>\n",
       "      <td>34.813141</td>\n",
       "      <td>115.559217</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>17:15</td>\n",
       "      <td>0.724306</td>\n",
       "      <td>-0.160743</td>\n",
       "      <td>-0.986996</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>0.246329</td>\n",
       "      <td>0.023061</td>\n",
       "      <td>0.999734</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-02-13 18:06:02</td>\n",
       "      <td>34.813278</td>\n",
       "      <td>115.559260</td>\n",
       "      <td>34.786126</td>\n",
       "      <td>115.874361</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>18:0</td>\n",
       "      <td>0.754167</td>\n",
       "      <td>0.026177</td>\n",
       "      <td>-0.999657</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>0.250595</td>\n",
       "      <td>-0.003740</td>\n",
       "      <td>0.999993</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            start_time  start_lat   start_lon    end_lat     end_lon  weekend  \\\n",
       "0  2018-01-20 10:13:43  33.783415  111.603660  33.779811  111.605885        1   \n",
       "1  2018-02-12 17:40:51  34.810763  115.549264  34.814875  115.549374        0   \n",
       "2  2018-02-13 14:52:24  34.640284  115.539024  34.813136  115.559243        0   \n",
       "3  2018-02-13 17:23:08  34.818280  115.542039  34.813141  115.559217        0   \n",
       "4  2018-02-13 18:06:02  34.813278  115.559260  34.786126  115.874361        0   \n",
       "\n",
       "   year  month  day time_cat  time_num  time_cos  time_sin   day_cat  \\\n",
       "0  2018      1   20     10:0  0.425694 -0.892979  0.450098  Saturday   \n",
       "1  2018      2   12    17:30  0.736111 -0.087156 -0.996195    Monday   \n",
       "2  2018      2   13    14:45  0.619444 -0.731354 -0.681998   Tuesday   \n",
       "3  2018      2   13    17:15  0.724306 -0.160743 -0.986996   Tuesday   \n",
       "4  2018      2   13     18:0  0.754167  0.026177 -0.999657   Tuesday   \n",
       "\n",
       "    day_num   day_cos   day_sin  \n",
       "0  0.775099  0.157050 -0.987591  \n",
       "1  0.105159  0.789543  0.613695  \n",
       "2  0.231349  0.116918  0.993142  \n",
       "3  0.246329  0.023061  0.999734  \n",
       "4  0.250595 -0.003740  0.999993  "
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hourDf['day_cos']=hourDf.apply(lambda row:day_cos(row['day_num']),axis=1)\n",
    "hourDf['day_sin']=hourDf.apply(lambda row:day_sin(row['day_num']),axis=1)\n",
    "processedDf.loc[:,\"day_cos\"] = hourDf.loc[:,\"day_cos\"]\n",
    "processedDf.loc[:,\"day_sin\"] = hourDf.loc[:,\"day_sin\"]\n",
    "processedDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "def x_start(lat_start,lon_start):\n",
    "    per = math.cos(lat_start)*math.cos(lon_start)\n",
    "    return per\n",
    "def y_start(lat_start,lon_start):\n",
    "    per = math.cos(lat_start)*math.sin(lon_start)\n",
    "    return per\n",
    "def z_start(lat_start):\n",
    "    per = math.sin(lat_start)\n",
    "    return per"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_time</th>\n",
       "      <th>start_lat</th>\n",
       "      <th>start_lon</th>\n",
       "      <th>end_lat</th>\n",
       "      <th>end_lon</th>\n",
       "      <th>weekend</th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>day</th>\n",
       "      <th>time_cat</th>\n",
       "      <th>time_num</th>\n",
       "      <th>time_cos</th>\n",
       "      <th>time_sin</th>\n",
       "      <th>day_cat</th>\n",
       "      <th>day_num</th>\n",
       "      <th>day_cos</th>\n",
       "      <th>day_sin</th>\n",
       "      <th>x_start</th>\n",
       "      <th>y_start</th>\n",
       "      <th>z_start</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018-01-20 10:13:43</td>\n",
       "      <td>33.783415</td>\n",
       "      <td>111.603660</td>\n",
       "      <td>33.779811</td>\n",
       "      <td>111.605885</td>\n",
       "      <td>1</td>\n",
       "      <td>2018</td>\n",
       "      <td>1</td>\n",
       "      <td>20</td>\n",
       "      <td>10:0</td>\n",
       "      <td>0.425694</td>\n",
       "      <td>-0.892979</td>\n",
       "      <td>0.450098</td>\n",
       "      <td>Saturday</td>\n",
       "      <td>0.775099</td>\n",
       "      <td>0.157050</td>\n",
       "      <td>-0.987591</td>\n",
       "      <td>-0.055090</td>\n",
       "      <td>0.712922</td>\n",
       "      <td>0.699076</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018-02-12 17:40:51</td>\n",
       "      <td>34.810763</td>\n",
       "      <td>115.549264</td>\n",
       "      <td>34.814875</td>\n",
       "      <td>115.549374</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>12</td>\n",
       "      <td>17:30</td>\n",
       "      <td>0.736111</td>\n",
       "      <td>-0.087156</td>\n",
       "      <td>-0.996195</td>\n",
       "      <td>Monday</td>\n",
       "      <td>0.105159</td>\n",
       "      <td>0.789543</td>\n",
       "      <td>0.613695</td>\n",
       "      <td>0.746854</td>\n",
       "      <td>-0.615984</td>\n",
       "      <td>-0.250546</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018-02-13 14:52:24</td>\n",
       "      <td>34.640284</td>\n",
       "      <td>115.539024</td>\n",
       "      <td>34.813136</td>\n",
       "      <td>115.559243</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>14:45</td>\n",
       "      <td>0.619444</td>\n",
       "      <td>-0.731354</td>\n",
       "      <td>-0.681998</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>0.231349</td>\n",
       "      <td>0.116918</td>\n",
       "      <td>0.993142</td>\n",
       "      <td>0.762286</td>\n",
       "      <td>-0.641939</td>\n",
       "      <td>-0.082670</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018-02-13 17:23:08</td>\n",
       "      <td>34.818280</td>\n",
       "      <td>115.542039</td>\n",
       "      <td>34.813141</td>\n",
       "      <td>115.559217</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>17:15</td>\n",
       "      <td>0.724306</td>\n",
       "      <td>-0.160743</td>\n",
       "      <td>-0.986996</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>0.246329</td>\n",
       "      <td>0.023061</td>\n",
       "      <td>0.999734</td>\n",
       "      <td>0.740919</td>\n",
       "      <td>-0.620137</td>\n",
       "      <td>-0.257816</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018-02-13 18:06:02</td>\n",
       "      <td>34.813278</td>\n",
       "      <td>115.559260</td>\n",
       "      <td>34.786126</td>\n",
       "      <td>115.874361</td>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>18:0</td>\n",
       "      <td>0.754167</td>\n",
       "      <td>0.026177</td>\n",
       "      <td>-0.999657</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>0.250595</td>\n",
       "      <td>-0.003740</td>\n",
       "      <td>0.999993</td>\n",
       "      <td>0.752481</td>\n",
       "      <td>-0.608090</td>\n",
       "      <td>-0.252980</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            start_time  start_lat   start_lon    end_lat     end_lon  weekend  \\\n",
       "0  2018-01-20 10:13:43  33.783415  111.603660  33.779811  111.605885        1   \n",
       "1  2018-02-12 17:40:51  34.810763  115.549264  34.814875  115.549374        0   \n",
       "2  2018-02-13 14:52:24  34.640284  115.539024  34.813136  115.559243        0   \n",
       "3  2018-02-13 17:23:08  34.818280  115.542039  34.813141  115.559217        0   \n",
       "4  2018-02-13 18:06:02  34.813278  115.559260  34.786126  115.874361        0   \n",
       "\n",
       "   year  month  day time_cat  time_num  time_cos  time_sin   day_cat  \\\n",
       "0  2018      1   20     10:0  0.425694 -0.892979  0.450098  Saturday   \n",
       "1  2018      2   12    17:30  0.736111 -0.087156 -0.996195    Monday   \n",
       "2  2018      2   13    14:45  0.619444 -0.731354 -0.681998   Tuesday   \n",
       "3  2018      2   13    17:15  0.724306 -0.160743 -0.986996   Tuesday   \n",
       "4  2018      2   13     18:0  0.754167  0.026177 -0.999657   Tuesday   \n",
       "\n",
       "    day_num   day_cos   day_sin   x_start   y_start   z_start  \n",
       "0  0.775099  0.157050 -0.987591 -0.055090  0.712922  0.699076  \n",
       "1  0.105159  0.789543  0.613695  0.746854 -0.615984 -0.250546  \n",
       "2  0.231349  0.116918  0.993142  0.762286 -0.641939 -0.082670  \n",
       "3  0.246329  0.023061  0.999734  0.740919 -0.620137 -0.257816  \n",
       "4  0.250595 -0.003740  0.999993  0.752481 -0.608090 -0.252980  "
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "processedDf['x_start']=processedDf.apply(lambda row:x_start(row['start_lat'],row['start_lon']),axis=1)\n",
    "processedDf['y_start']=processedDf.apply(lambda row:y_start(row['start_lat'],row['start_lon']),axis=1)\n",
    "processedDf['z_start']=processedDf.apply(lambda row:z_start(row['start_lat']),axis=1)\n",
    "processedDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "def location(lat,lon):\n",
    "    per = geohash.encode(lat,lon,9)\n",
    "    return per"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "processedDf['location_start']=processedDf.apply(lambda row:location(row['start_lat'],row['start_lon']),axis=1)\n",
    "processedDf['location_end']=processedDf.apply(lambda row:location(row['end_lat'],row['end_lon']),axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>weekend</th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>day</th>\n",
       "      <th>time_cat</th>\n",
       "      <th>time_num</th>\n",
       "      <th>time_cos</th>\n",
       "      <th>time_sin</th>\n",
       "      <th>day_cat</th>\n",
       "      <th>day_num</th>\n",
       "      <th>day_cos</th>\n",
       "      <th>day_sin</th>\n",
       "      <th>x_start</th>\n",
       "      <th>y_start</th>\n",
       "      <th>z_start</th>\n",
       "      <th>location_start</th>\n",
       "      <th>location_end</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2018</td>\n",
       "      <td>1</td>\n",
       "      <td>20</td>\n",
       "      <td>10:0</td>\n",
       "      <td>0.425694</td>\n",
       "      <td>-0.892979</td>\n",
       "      <td>0.450098</td>\n",
       "      <td>Saturday</td>\n",
       "      <td>0.775099</td>\n",
       "      <td>0.157050</td>\n",
       "      <td>-0.987591</td>\n",
       "      <td>-0.055090</td>\n",
       "      <td>0.712922</td>\n",
       "      <td>0.699076</td>\n",
       "      <td>wqp25w569</td>\n",
       "      <td>wqp25tkvt</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>12</td>\n",
       "      <td>17:30</td>\n",
       "      <td>0.736111</td>\n",
       "      <td>-0.087156</td>\n",
       "      <td>-0.996195</td>\n",
       "      <td>Monday</td>\n",
       "      <td>0.105159</td>\n",
       "      <td>0.789543</td>\n",
       "      <td>0.613695</td>\n",
       "      <td>0.746854</td>\n",
       "      <td>-0.615984</td>\n",
       "      <td>-0.250546</td>\n",
       "      <td>ww4nj3h7m</td>\n",
       "      <td>ww4nj3u7r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>14:45</td>\n",
       "      <td>0.619444</td>\n",
       "      <td>-0.731354</td>\n",
       "      <td>-0.681998</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>0.231349</td>\n",
       "      <td>0.116918</td>\n",
       "      <td>0.993142</td>\n",
       "      <td>0.762286</td>\n",
       "      <td>-0.641939</td>\n",
       "      <td>-0.082670</td>\n",
       "      <td>ww4jj4hfq</td>\n",
       "      <td>ww4nj9e9j</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>17:15</td>\n",
       "      <td>0.724306</td>\n",
       "      <td>-0.160743</td>\n",
       "      <td>-0.986996</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>0.246329</td>\n",
       "      <td>0.023061</td>\n",
       "      <td>0.999734</td>\n",
       "      <td>0.740919</td>\n",
       "      <td>-0.620137</td>\n",
       "      <td>-0.257816</td>\n",
       "      <td>ww4nj4rph</td>\n",
       "      <td>ww4nj9e9h</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>18:0</td>\n",
       "      <td>0.754167</td>\n",
       "      <td>0.026177</td>\n",
       "      <td>-0.999657</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>0.250595</td>\n",
       "      <td>-0.003740</td>\n",
       "      <td>0.999993</td>\n",
       "      <td>0.752481</td>\n",
       "      <td>-0.608090</td>\n",
       "      <td>-0.252980</td>\n",
       "      <td>ww4nj9edj</td>\n",
       "      <td>ww4muu95u</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   weekend  year  month  day time_cat  time_num  time_cos  time_sin   day_cat  \\\n",
       "0        1  2018      1   20     10:0  0.425694 -0.892979  0.450098  Saturday   \n",
       "1        0  2018      2   12    17:30  0.736111 -0.087156 -0.996195    Monday   \n",
       "2        0  2018      2   13    14:45  0.619444 -0.731354 -0.681998   Tuesday   \n",
       "3        0  2018      2   13    17:15  0.724306 -0.160743 -0.986996   Tuesday   \n",
       "4        0  2018      2   13     18:0  0.754167  0.026177 -0.999657   Tuesday   \n",
       "\n",
       "    day_num   day_cos   day_sin   x_start   y_start   z_start location_start  \\\n",
       "0  0.775099  0.157050 -0.987591 -0.055090  0.712922  0.699076      wqp25w569   \n",
       "1  0.105159  0.789543  0.613695  0.746854 -0.615984 -0.250546      ww4nj3h7m   \n",
       "2  0.231349  0.116918  0.993142  0.762286 -0.641939 -0.082670      ww4jj4hfq   \n",
       "3  0.246329  0.023061  0.999734  0.740919 -0.620137 -0.257816      ww4nj4rph   \n",
       "4  0.250595 -0.003740  0.999993  0.752481 -0.608090 -0.252980      ww4nj9edj   \n",
       "\n",
       "  location_end  \n",
       "0    wqp25tkvt  \n",
       "1    ww4nj3u7r  \n",
       "2    ww4nj9e9j  \n",
       "3    ww4nj9e9h  \n",
       "4    ww4muu95u  "
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "processedDf.drop(['start_time','start_lat','start_lon','end_lat','end_lon'],axis=1,inplace=True)\n",
    "processedDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>year</th>\n",
       "      <th>month</th>\n",
       "      <th>day</th>\n",
       "      <th>time_cat</th>\n",
       "      <th>time_num</th>\n",
       "      <th>time_cos</th>\n",
       "      <th>time_sin</th>\n",
       "      <th>day_cat</th>\n",
       "      <th>day_num</th>\n",
       "      <th>day_cos</th>\n",
       "      <th>day_sin</th>\n",
       "      <th>weekend</th>\n",
       "      <th>x_start</th>\n",
       "      <th>y_start</th>\n",
       "      <th>z_start</th>\n",
       "      <th>location_start</th>\n",
       "      <th>location_end</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2018</td>\n",
       "      <td>1</td>\n",
       "      <td>20</td>\n",
       "      <td>10:0</td>\n",
       "      <td>0.425694</td>\n",
       "      <td>-0.892979</td>\n",
       "      <td>0.450098</td>\n",
       "      <td>Saturday</td>\n",
       "      <td>0.775099</td>\n",
       "      <td>0.157050</td>\n",
       "      <td>-0.987591</td>\n",
       "      <td>1</td>\n",
       "      <td>-0.055090</td>\n",
       "      <td>0.712922</td>\n",
       "      <td>0.699076</td>\n",
       "      <td>wqp25w569</td>\n",
       "      <td>wqp25tkvt</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>12</td>\n",
       "      <td>17:30</td>\n",
       "      <td>0.736111</td>\n",
       "      <td>-0.087156</td>\n",
       "      <td>-0.996195</td>\n",
       "      <td>Monday</td>\n",
       "      <td>0.105159</td>\n",
       "      <td>0.789543</td>\n",
       "      <td>0.613695</td>\n",
       "      <td>0</td>\n",
       "      <td>0.746854</td>\n",
       "      <td>-0.615984</td>\n",
       "      <td>-0.250546</td>\n",
       "      <td>ww4nj3h7m</td>\n",
       "      <td>ww4nj3u7r</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>14:45</td>\n",
       "      <td>0.619444</td>\n",
       "      <td>-0.731354</td>\n",
       "      <td>-0.681998</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>0.231349</td>\n",
       "      <td>0.116918</td>\n",
       "      <td>0.993142</td>\n",
       "      <td>0</td>\n",
       "      <td>0.762286</td>\n",
       "      <td>-0.641939</td>\n",
       "      <td>-0.082670</td>\n",
       "      <td>ww4jj4hfq</td>\n",
       "      <td>ww4nj9e9j</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>17:15</td>\n",
       "      <td>0.724306</td>\n",
       "      <td>-0.160743</td>\n",
       "      <td>-0.986996</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>0.246329</td>\n",
       "      <td>0.023061</td>\n",
       "      <td>0.999734</td>\n",
       "      <td>0</td>\n",
       "      <td>0.740919</td>\n",
       "      <td>-0.620137</td>\n",
       "      <td>-0.257816</td>\n",
       "      <td>ww4nj4rph</td>\n",
       "      <td>ww4nj9e9h</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2018</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>18:0</td>\n",
       "      <td>0.754167</td>\n",
       "      <td>0.026177</td>\n",
       "      <td>-0.999657</td>\n",
       "      <td>Tuesday</td>\n",
       "      <td>0.250595</td>\n",
       "      <td>-0.003740</td>\n",
       "      <td>0.999993</td>\n",
       "      <td>0</td>\n",
       "      <td>0.752481</td>\n",
       "      <td>-0.608090</td>\n",
       "      <td>-0.252980</td>\n",
       "      <td>ww4nj9edj</td>\n",
       "      <td>ww4muu95u</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   year  month  day time_cat  time_num  time_cos  time_sin   day_cat  \\\n",
       "0  2018      1   20     10:0  0.425694 -0.892979  0.450098  Saturday   \n",
       "1  2018      2   12    17:30  0.736111 -0.087156 -0.996195    Monday   \n",
       "2  2018      2   13    14:45  0.619444 -0.731354 -0.681998   Tuesday   \n",
       "3  2018      2   13    17:15  0.724306 -0.160743 -0.986996   Tuesday   \n",
       "4  2018      2   13     18:0  0.754167  0.026177 -0.999657   Tuesday   \n",
       "\n",
       "    day_num   day_cos   day_sin  weekend   x_start   y_start   z_start  \\\n",
       "0  0.775099  0.157050 -0.987591        1 -0.055090  0.712922  0.699076   \n",
       "1  0.105159  0.789543  0.613695        0  0.746854 -0.615984 -0.250546   \n",
       "2  0.231349  0.116918  0.993142        0  0.762286 -0.641939 -0.082670   \n",
       "3  0.246329  0.023061  0.999734        0  0.740919 -0.620137 -0.257816   \n",
       "4  0.250595 -0.003740  0.999993        0  0.752481 -0.608090 -0.252980   \n",
       "\n",
       "  location_start location_end  \n",
       "0      wqp25w569    wqp25tkvt  \n",
       "1      ww4nj3h7m    ww4nj3u7r  \n",
       "2      ww4jj4hfq    ww4nj9e9j  \n",
       "3      ww4nj4rph    ww4nj9e9h  \n",
       "4      ww4nj9edj    ww4muu95u  "
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "processedDf=processedDf.reindex_axis([\"year\",\"month\",\"day\",\n",
    "                                      \"time_cat\",\"time_num\",\"time_cos\",\"time_sin\",\n",
    "                                      \"day_cat\",\"day_num\",\"day_cos\",\"day_sin\",\n",
    "                                      \"weekend\",\n",
    "                                      \"x_start\",\"y_start\",\"z_start\",\n",
    "                                      \"location_start\",\"location_end\"],axis=1)\n",
    "processedDf.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "processedDf.to_csv('featured-dataset_new.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
